package cool.tianyou.blue.bird.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

public class JSONUtil {
    public static <T> T parseObject(Object object, Class<T> targetClass) {
        if (object instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) object;
            return jsonObject.toJavaObject(targetClass);
        }
        throw new RuntimeException("无法转换");
    }

    public static <T> List<T> parseArray(Object object, Class<T> targetClass) {
        if (object instanceof JSONArray) {
            JSONArray jsonArray = (JSONArray) object;
            return jsonArray.toJavaList(targetClass);
        }

        throw new RuntimeException("无法将对象转换为list");
    }
}
